//    Sofa Control is a computer remote control designed for handheld devices
//    Copyright (C) 2009 Adrián Romero Corchado
//    http://code.google.com/p/sofacontrol/
//
//    This file is part of Sofa Control.
//
//    Sofa Control is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    Sofa Control is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with Sofa Control.  If not, see <http://www.gnu.org/licenses/>.

package org.arc.sofacontrol.proc;

import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author adrianromero
 */
public class KeyMap {
    
    private Robot robot;
    private Map<String, KeySequence> keys = new HashMap<String, KeySequence>();
    
    public KeyMap(Robot robot) {
        
        this.robot = robot;
    
        put(new KeySequence("a", KeyEvent.VK_A));
        put(new KeySequence("b", KeyEvent.VK_B));
        put(new KeySequence("c", KeyEvent.VK_C));
        put(new KeySequence("d", KeyEvent.VK_D));
        put(new KeySequence("e", KeyEvent.VK_E));
        put(new KeySequence("f", KeyEvent.VK_F));
        put(new KeySequence("g", KeyEvent.VK_G));
        put(new KeySequence("h", KeyEvent.VK_H));
        put(new KeySequence("i", KeyEvent.VK_I));
        put(new KeySequence("j", KeyEvent.VK_J));
        put(new KeySequence("k", KeyEvent.VK_K));
        put(new KeySequence("l", KeyEvent.VK_L));
        put(new KeySequence("m", KeyEvent.VK_M));
        put(new KeySequence("n", KeyEvent.VK_N));
        put(new KeySequence("o", KeyEvent.VK_O));
        put(new KeySequence("p", KeyEvent.VK_P));
        put(new KeySequence("q", KeyEvent.VK_Q));
        put(new KeySequence("r", KeyEvent.VK_R));
        put(new KeySequence("s", KeyEvent.VK_S));
        put(new KeySequence("t", KeyEvent.VK_T));
        put(new KeySequence("u", KeyEvent.VK_U));
        put(new KeySequence("v", KeyEvent.VK_V));
        put(new KeySequence("w", KeyEvent.VK_W));
        put(new KeySequence("w", KeyEvent.VK_X));
        put(new KeySequence("y", KeyEvent.VK_Y));
        put(new KeySequence("z", KeyEvent.VK_Z));
        
        put(new KeySequence("0", KeyEvent.VK_0));
        put(new KeySequence("1", KeyEvent.VK_1));
        put(new KeySequence("2", KeyEvent.VK_2));
        put(new KeySequence("3", KeyEvent.VK_3));
        put(new KeySequence("4", KeyEvent.VK_4));
        put(new KeySequence("5", KeyEvent.VK_5));
        put(new KeySequence("6", KeyEvent.VK_6));
        put(new KeySequence("7", KeyEvent.VK_7));
        put(new KeySequence("8", KeyEvent.VK_8));
        put(new KeySequence("9", KeyEvent.VK_9));
        
        put(new KeySequence("UP", KeyEvent.VK_UP));
        put(new KeySequence("DOWN", KeyEvent.VK_DOWN));
        put(new KeySequence("RIGHT", KeyEvent.VK_RIGHT));
        put(new KeySequence("LEFT", KeyEvent.VK_LEFT));
        put(new KeySequence("ENTER", KeyEvent.VK_ENTER));
        put(new KeySequence("SPACE", KeyEvent.VK_SPACE));
        put(new KeySequence(".", KeyEvent.VK_PERIOD));
        put(new KeySequence(",", KeyEvent.VK_COMMA));
        put(new KeySequence("-", KeyEvent.VK_MINUS));

        put(new KeySequence("VOLUME+", 176));
        put(new KeySequence("VOLUME-", 174));
        put(new KeySequence("VOLUMEMUTE", 160));
        put(new KeySequence("AUDIOPLAY", 162));
        put(new KeySequence("AUDIOPREV", 144));
        put(new KeySequence("AUDIONEXT", 153));
        put(new KeySequence("AUDIOSTOP", 164));        
        
        put(new KeySequence("CHANNEL+", KeyEvent.VK_PLUS));
        put(new KeySequence("CHANNEL-", KeyEvent.VK_MINUS));
        
        put(new KeySequence("ESC", KeyEvent.VK_ESCAPE));
        put(new KeySequence("SPACE", KeyEvent.VK_SPACE));
        put(new KeySequence("BACK", KeyEvent.VK_BACK_SPACE));
        put(new KeySequence("SHIFT", KeyEvent.VK_SHIFT));

        
        
    }
    
    public void put(KeySequence k) {
        keys.put(k.getValue(), k);
    }
    
    public void exec(String value) {
        
        KeySequence ks = keys.get(value);
        if (ks != null) {
            ks.exec(robot);
        }
    }
}
